#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：Employment_class 
@File    ：03_HTTPX_.py
@IDE     ：PyCharm 
@Author  ：XiaoDengYa
@Date    ：2021/8/16/016 16:00 
"""

import httpx

# r = httpx.get('https://httpbin.org/get')
# print(r.status_code)
#
# r = httpx.post('https://httpbin.org/post', data={'key': 'value'})
#
# print(r.text)
#
# params = {'key1': 'value1', 'key2': 'value2'}
# r = httpx.get('https://httpbin.org/get', params=params)

# params = {'key1': 'value1', 'key2': ['value2', 'value3']}
#
# r = httpx.get('https://httpbin.org/get', params=params)
# print(r.url)

# r = httpx.get('https://www.example.org/')
# print(r.text)
# print(r.encoding)

# r = httpx.get('https://api.github.com/events')
# print(r.json())
# print(r.text)

# url = 'http://httpbin.org/headers'
# headers = {'user-agent': 'my-app/0.0.1'}
# r = httpx.get(url, headers=headers)


# data = {'key1': 'value1', 'key2': 'value2'}
# r = httpx.post("https://httpbin.org/post", data=data)
# print(r.text)

# r = httpx.get('https://httpbin.org/get')
# print(r.status_code == httpx.codes.OK)


# not_found = httpx.get('https://httpbin.org/status/404')
# print(not_found.status_code)

# with httpx.stream("GET", "https://www.example.com") as r:
#     for data in r.iter_bytes():
#         print(data)

# r = httpx.get('http://httpbin.org/cookies/set?chocolate=chip', allow_redirects=False)
#
# print(r.cookies['chocolate'])

r = httpx.get('http://github.com/')
print(r.url)
print(r.status_code)
print(r.history)

r = httpx.get('http://github.com/', allow_redirects=False)
print(r.url)
print(r.status_code)
print(r.history)